package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.GlueIngredients;
import com.ruoyi.system.mapper.GlueIngredientsMapper;
import com.ruoyi.system.service.IGlueCategoryService;
import com.ruoyi.system.service.IGlueIngredientsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * 辅料信息Service业务层处理
 *
 * @author ruoyi
 * @date 2025-03-31
 */
@Service
public class GlueIngredientsServiceImpl extends ServiceImpl<GlueIngredientsMapper,GlueIngredients> implements IGlueIngredientsService
{
    @Autowired
    private GlueIngredientsMapper glueIngredientsMapper;

    @Autowired
    private IGlueCategoryService glueCategoryService;

    /**
     * 查询辅料信息
     *
     * @param id 辅料信息主键
     * @return 辅料信息
     */
    @Override
    public GlueIngredients selectGlueIngredientsById(Long id)
    {
        return glueIngredientsMapper.selectGlueIngredientsById(id);
    }

    /**
     * 查询辅料信息列表
     *
     * @param glueIngredients 辅料信息
     * @return 辅料信息
     */
    @Override
    public List<GlueIngredients> selectGlueIngredientsList(GlueIngredients glueIngredients)
    {
        //有值就递归查出所有子集
        if (!ObjectUtils.isEmpty(glueIngredients.getClassifyId())){
            List<Long> ids = glueCategoryService.getIds(glueIngredients.getClassifyId());
            glueIngredients.setClassifyIds(ids);
        }

        return glueIngredientsMapper.selectGlueIngredientsList(glueIngredients);
    }

    /**
     * 新增辅料信息
     *
     * @param glueIngredients 辅料信息
     * @return 结果
     */
    @Override
    public int insertGlueIngredients(GlueIngredients glueIngredients)
    {
        glueIngredients.setCreateTime(DateUtils.getNowDate());
        glueIngredients.setCreateBy(SecurityUtils.getUserId().toString());
        return glueIngredientsMapper.insertGlueIngredients(glueIngredients);
    }

    /**
     * 修改辅料信息
     *
     * @param glueIngredients 辅料信息
     * @return 结果
     */
    @Override
    public int updateGlueIngredients(GlueIngredients glueIngredients)
    {
        glueIngredients.setUpdateTime(DateUtils.getNowDate());
        return glueIngredientsMapper.updateGlueIngredients(glueIngredients);
    }

    /**
     * 批量删除辅料信息
     *
     * @param ids 需要删除的辅料信息主键
     * @return 结果
     */
    @Override
    public int deleteGlueIngredientsByIds(Long[] ids)
    {
        return glueIngredientsMapper.deleteGlueIngredientsByIds(ids);
    }

    /**
     * 删除辅料信息信息
     *
     * @param id 辅料信息主键
     * @return 结果
     */
    @Override
    public int deleteGlueIngredientsById(Long id)
    {
        return glueIngredientsMapper.deleteGlueIngredientsById(id);
    }


    /**
     * 辅料名称三级目录
     * @param dto
     * @return
     */
    @Override
    public List<String> getModel(String dto) {
      return   glueIngredientsMapper.getModel(dto);
    }
}
